﻿using BussinessObject;
using Class_Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class WebApplication_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["RoleCode"] != null)
        {
            Response.Redirect("Default.aspx");
        }
    }
    protected void btLogin_Click(object sender, EventArgs e)
    {
        BOUsers bo = new BOUsers();
        Users us = new Users();

        us.Username = txtUsername.Text.Trim();
        us.Password = txtPassword.Text.Trim();

        bo.LoginAccounts(us);
        if (bo.LoginAccounts(us).Tables[0].Rows.Count > 0)
        {
            if (Convert.ToInt32(bo.LoginAccounts(us).Tables[0].Rows[0][2]) == 1)
            {
                Session["RoleCode"] = bo.LoginAccounts(us).Tables[0].Rows[0][2];
                Session["Username"] = us.Username;
                HttpContext.Current.Response.Write("<script type='text/javascript'>alert('" + "Login Successfully ..." + "');window.location.href='Default.aspx';</script>");
            }
            if (Convert.ToInt32(bo.LoginAccounts(us).Tables[0].Rows[0][2]) == 2)
            {
                Session["RoleCode"] = bo.LoginAccounts(us).Tables[0].Rows[0][2];
                Session["Username"] = us.Username;
                HttpContext.Current.Response.Write("<script type='text/javascript'>alert('" + "Login Successfully ..." + "');window.location.href='ADAccounts.aspx';</script>");
            }
            if (Convert.ToInt32(bo.LoginAccounts(us).Tables[0].Rows[0][2]) == 3)
            {
                Session["RoleCode"] = bo.LoginAccounts(us).Tables[0].Rows[0][2];
                Session["Username"] = us.Username;
                HttpContext.Current.Response.Write("<script type='text/javascript'>alert('" + "Login Successfully ..." + "');window.location.href='ADResume.aspx';</script>");
            }
        }
        else
        {
            HttpContext.Current.Response.Write("<script type='text/javascript'>alert('" + "Login Fail ..." + "');window.location.href='Login.aspx';</script>");
        }
    }
    protected void btnReg_Click(object sender, EventArgs e)
    {
        Response.Redirect("RegisterForm.aspx");
    }
}